package request;

public class Utils {

    public static void main(String[] args) {
//        getPtLocalTk("9237BD11FA08009D61FED5D9249BD69CD90AB0B5535DD624520E57AABB8C3531E3BCB2CF83DB6CF3ECC39C29AA8A5BEDB17ED0C96AC7AC91C95A9FC59EC72089");
        getBkn("@MV9JyTim4");
    }

    //hash33
    public static long getPtLocalTk(String clientkey){
        int e = 0;
        int n = clientkey.length();
        for (int i = 0; i < n; ++i)
            e += (e << 5) + unicode(clientkey.charAt(i));
        long pt_local_tk =  2147483647 & e;
        System.out.println("pt_local_tk="+pt_local_tk);
        return pt_local_tk;
    }

    public static int unicode(char source){
        return Integer.parseInt(Integer.toHexString(source), 16);
    }


    public static String getPtsigx(String url){
//        url = "https://ptlogin2.qun.qq.com/check_sig?pttype=2&uin=3319661457&service=jump&nodirect=0"
//                + "&ptsigx=4b8a33a721e10b244571843fe8cbbc4154d3a44c7691eb3668203dd4e31b6363d218452056eb1a3374c67727241fbad157e36051d2a969b97c6f99f843854bde"
//                + "&s_url=https%3A%2F%2Fqun.qq.com%2Fmanage.html&f_url=&ptlang=2052&ptredirect=100&aid=1000101&daid=73&j_later=0&low_login_hour=0&regmaster=0"
//                + "&pt_login_type=-1&pt_aid=715030901&pt_aaid=0&pt_light=0&pt_3rd_aid=0";
        int start = url.indexOf("ptsigx")+7;
        int end = url.substring(start).indexOf("&");
        return url.substring(start, start+end);
    }


    //@MV9JyTim4
    public static long getBkn(String skey){
        int r = 5381;
        int o = skey.length();
        for (int n = 0; o > n; ++n)
            r += (r << 5) + unicode(skey.charAt(n));
        long bkn = 2147483647 & r;
        System.out.println("bkn="+bkn);
        return bkn;
    }
}
